London | 26-ITP-May | Raihan Sharif | Sprint 2 | Coursework#1303
Open
RaihanSharif wants to merge 7 commits intoCodeYourFuture:mainfrom
Open
London | 26-ITP-May | Raihan Sharif | Sprint 2 | Coursework#1303RaihanSharif wants to merge 7 commits intoCodeYourFuture:mainfrom
RaihanSharif wants to merge 7 commits intoCodeYourFuture:mainfrom
Conversation
cjyuan
reviewed
May 10, 2026
| function calculateBMI(weight, height) { | ||
| // return the BMI of someone based off their weight and height | ||
| } No newline at end of file | ||
| return (weight / height ** 2).toFixed(1); |
Contributor
There was a problem hiding this comment.
What type of value do you expect your function to return? A number or a string?
Does your function return the type of value you expect?
Different types of values may appear identical in the console output, but they are represented and treated differently in the program. For example,
console.log(123); // Output 123
console.log("123"); // Output 123
// Treated differently in the program
let sum1 = 123 + 100; // Evaluate to 223 -- a number
let sum 2 = "123" + 100; // Evaluate to "123100" -- a string.
Author
There was a problem hiding this comment.
I have added type conversion to cast string to Number, or return NaN if not possible to cast.
cast to Number, or return NaN if not posible to do so.
cjyuan
reviewed
May 10, 2026
|
|
||
| function calculateBMI(weight, height) { | ||
| return (weight / height ** 2).toFixed(1); | ||
| return (Number(weight) / Number(height) ** 2).toFixed(1); |
Contributor
There was a problem hiding this comment.
How you checked if the return value is a number and not a string after you made the changes?
Author
There was a problem hiding this comment.
I did not. Now it's fixed.
Check the input, convert to Number if possible, else return NaN. Output is a Number.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Learners, PR Template
Self checklist
Changelist
Tasks done as per spec. Ran the code to see if it works.